package appBCN.version;

import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;
import android.widget.TextView;
import appBCN.DAL.PersonDAL;
import appBCN.MOs.Person;

public class AppBCNActivity extends Activity {
	private EditText mTextSearch; 
	private TextView mErrorTextMain;
	private Person user;
	
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    	user = new PersonDAL().GetUserByDNI("");
    	AppBCNApplication.getInstance().setPerson(user);
    }
    
    public void onStart_click(View view)
    {
    	ProgressDialog dialog = ProgressDialog.show(AppBCNActivity.this, "", "Loading. Please wait...", true);
    	mTextSearch = (EditText)findViewById(R.id.widget32);
    	String text = mTextSearch.getText().toString();
    	if(user.getCip().equals(text))
    	{
    		Intent intent= new Intent( view.getContext(), HomeActivity.class) ;
        	startActivity( intent );
    	}
    	else
    	{
    		mErrorTextMain = (TextView)findViewById(R.id.textViewError);
    		mErrorTextMain.setText("Codi incorrecto");
    	}
    	mTextSearch.setText("");
		InputMethodManager mgr = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
    	mgr.hideSoftInputFromInputMethod(mTextSearch.getWindowToken(), 0);
    	dialog.hide();
    }
}